home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / vlclass.exe / VOLLAB.H < prev   
C/C++ Source or Header  |  1991-11-20  |  2KB  |  60 lines

  1. /* Volume Label Class
  2.    By Tom Astin 73407,3427
  3.    Copyright 1991
  4.  
  5.    Below is a quick hack to Get, Set, and Remove the volume label from a
  6.    DOS disk.  It has not been tested more than once on a floppy disk so
  7.    use at your own risk.
  8.  
  9.    Dos will return AL=0xFF on most of these fcb functions that fail.
  10.    AL=0xFF doesn't neccessarily mean a major general failure.
  11.       (ie: Dos label isn't there).
  12.    IsError() will return non-zero if an abonormal dos error occurs.
  13.    Does not trap fatal errors. (int 24)
  14.    *** All drive parameters are as follows: 0=Current, 1=A, 2=B, etc.
  15.    *** Caller is not responsible for any heap deallocation except for
  16.        object instance (ie: returned char* are not on heap).
  17. */
  18.  
  19. #include <dos.h>
  20. #include <string.h>
  21.  
  22. class VolLabel {
  23.     xfcb    xf,*pxf;    // xf is general xfcb, pxf will point to buf.
  24.     char    *buf[64];   // temp dta
  25.     struct {             // special FCB
  26.         char flg;
  27.         char r1[5];
  28.         char attr;
  29.         char dr;
  30.         char oldn[11];
  31.         char r2[5];
  32.         char newn[11];
  33.         char r3[9];
  34.     } fcbSpec;
  35.     void SetupXFCB();    // fill in default fields of xf
  36.     int bDosErr;        // boolean Dos Error?
  37.     unsigned int res;   // last AX return from dos fcb functions
  38.     void CustomDos(unsigned char ah, void far *data); // our dos caller
  39.     unsigned short SectorSize(int nDrive); // return physical sector size
  40. public:
  41.     char *GetLabel(int nDrive);
  42.       // return char * to the current label for specified drive
  43.       // return NULL if no label present
  44.     int SetLabel(int nDrive, char *szLabel);
  45.       // change the current label for the specified drive
  46.       // return non-zero on success
  47.     int Remove(int nDrive);
  48.       // remove the current label so there will be none.
  49.       // return non-zero on success
  50.     inline int IsError() {return bDosErr;}
  51.       // return non-zero on major dos error
  52.     inline unsigned ErrorCode() {return res;}
  53.       // return AX value returned from function
  54.     unsigned long GetSerial(unsigned char nDrive);
  55.       // return unsigned long serial number from boot record
  56.     int SetSerial(unsigned char nDrive, unsigned long nSerial);
  57.       // set the serial # by modifying disk boot record
  58.     unsigned char GetDisk();
  59. };
  60.